package LeetCode.leetcode111;

import java.util.HashMap;
import java.util.HashSet;

public class Review1 {
    public int minDepth(TreeNode root) {
        if (root == null) return 0;
        return min(root,1);
    }
    public static int min(TreeNode node, int res){
        if (node.left == null && node.right == null){
            return res;
        }else if (node.left != null && node.right == null){
            return min(node.left,res+1);
        }else if (node.left == null && node.right != null){
            return min(node.right,res+1);
        }else {
            return Math.min(min(node.left,res+1),min(node.right,res+1));
        }
    }
}
